<?php
    $firstContent = $otherContent = array();
    $curDay = date('d-m-Y',time());
    $minusDay = date('d-m-Y', strtotime ( '-3 day' . $curDay ) ); 
    $minusDay = strtotime($minusDay);
    //Lấy node type tin tuc
    $opt = array(
        'conditions' => array('NodeType.id' => 3),
        'fields' => array('NodeType.id','NodeType.name'),
        'locale' => true,
        'find' => 'first'
    );    
    $nodeType = $this->String->get_data('Node','NodeType',$opt);
    //Lay danh sach slide
    $content = array();
    $condsDefault = $this->String->condsDefault();
    $condsDefault = array_merge($condsDefault,array('NOT' => array('NodeTerm.term_id' => 3),'Node.node_type_id' => 3));
    $fields = $this->String->nodeFields();
    $fields = array_merge($fields,array('Node.field_embed_youtube','Node.field_attach_file')); 
    $order = $this->String->orderFields();
    $opt = array(
        'conditions' => $condsDefault,
        'find' => 'all',
        'fields' => $fields,
        'locale' => true,
        'order' => $order
    );
    $content = $this->String->get_data('Node','NodeTerm',$opt); 
    if(!empty($content)){
        foreach($content as $x=>$y){
            $term = ClassRegistry::init('Node.Term')->find('first',array(
                    'conditions' => array('Term.id' => $y['NodeTerm']['term_id']),
                    'recursive' => -1
                ));
            $content[$x]['Term'] = $term['Term'];
        }
        $firstContent = $content[0];
        unset($content[0]);
        if(count($content)>0){
            $otherContent = $content;
        }
    }
    $k = 1;$arrNew = array();
    $i = 0;
    if(!empty($otherContent)){
        foreach($otherContent as $key => $values){
            if($i%5==0) $k++;
            $arrNew[$k][] = $values;
            $i++; 
        }
    }
?>

<div class="tabpanel-cus" role="tabpanel">
    <!-- Nav tabs -->
    <ul class="nav nav-tabs mytabs-cus mytabs-nbdcus">
        <li class="item item-onl-tab active"><a href="#item-21" data-toggle="tab"><?php echo $nodeType['NodeType']['name'];?></a></li>
    </ul>
    <!-- Tab panes -->
    <div class="tab-content">
        <div class="tab-pane tab-pane-bgtop fade in active" id="item-21">
            <div class="tabs-pane-content-full">
                <div class="row">
                    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 col-cus-lct">
                        <?php if(!empty($firstContent)):?>
                            <?php 
                                if((!empty($firstContent['Node']['field_image_default']))&&(file_exists(WWW_ROOT . '/img/' . $firstContent['Node']['field_image_default'])))
                                {
                                    $thumb_pro = $this->Image->make_thumb($firstContent['Node']['field_image_default'],WWW_ROOT . '/img/','292','168');
                                }
                                else
                                {
                                    $thumb_pro = $this->Image->make_thumb('no_image.jpg',WWW_ROOT.'/img/','291','168');
                                }
                            ?>
                            <div class="block-hns">
                                <h3 class="title-smbl"><a href="<?php echo $this->Html->url(array('plugin' => 'View','controller' => 'View','action' => 'news',$firstContent['Term']['alias'],$firstContent['Node']['alias']))?>"><?php echo String::truncate($firstContent['Node']['title'],90);?>
                                        <?php if($firstContent['Node']['created']>$minusDay):?>
                                            <img src="<?php echo $this->Html->webroot('/images/front/newvn.gif');?>" alt="new" height="19" width="29" class="image-news">
                                            <?php endif;?>
                                    </a></h3>
                                <div class="block-hns-content">
                                    <a href="<?php echo $this->Html->url(array('plugin' => 'View','controller' => 'View','action' => 'news',$firstContent['Term']['alias'],$firstContent['Node']['alias']))?>" class="img-link">
                                        <img src="<?php echo $this->Html->webroot('/img/' . $thumb_pro);?>" alt="new" height="186" width="322" class="image">
                                    </a>
                                    <p class="desc-ct"><?php echo String::truncate($firstContent['Node']['field_description'],250);?></p>
                                </div>
                            </div>
                            <?php endif;?>
                    </div>
                    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 col-cus-rct">
                        <div class="block-hns-oth">
                            <?php if(!empty($arrNew)):?>
                                <h3 class="tit-bd"><?php echo __d('default','CÁC TIN KHÁC');?></h3>
                                <div class="asbl-rct-cus-slide">
                                    <div class="flexslider flexslider-cal">
                                        <ul class="slides">
                                            <?php foreach($arrNew as $key => $values):?>
                                                <li>
                                                    <ul class="news-list-mnth">
                                                        <?php foreach($values as $chidlKey => $childValues):?>
                                                            <li class="item">
                                                                <p class="tt-desc"><a href="<?php echo $this->Html->url(array('plugin' => 'View','controller' => 'View','action' => 'news',$childValues['Term']['alias'],$childValues['Node']['alias']))?>" class="ttlk"><?php echo String::truncate($childValues['Node']['title'],80);?></a></p>
                                                            </li>
                                                            <?php endforeach;?>
                                                    </ul>
                                                </li>
                                                <?php endforeach;?>
                                        </ul>
                                    </div>
                                    <p class="tar">
                                        <a href="<?php echo $this->Html->url(array('plugin' => 'View','controller' => 'View','action' => 'news','tin-di-tru-my'))?>" class="show-more-link"><?php echo __d('default','Xem thêm');?> »</a>
                                    </p>
                                </div>
                                <?php endif;?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
